<!-- html -->
<template>
  <h2 class="h2">{{ title1 }}</h2>
  <span class="span3">父组件</span>
  <br>
  <span class="span2">内容：{{ text }}</span>
  <button class="button1" @click="changeText">修改内容</button>
  <hr class="hr1">
  <span class="span3">子组件</span>
  <br>
  <propsTest2Child1 v-bind:parentText="text" v-bind:parentChangeText="changeText" />
  <hr class="hr2">
  <h2 class="h2">{{ title2 }}</h2>
  <span class="span3">父组件</span>
  <br>
  <span class="span2">子组件内容：{{ childText }}</span>
  <button class="button1" @click="changeChildText">修改内容</button>
  <hr class="hr1">
  <span class="span3">子组件</span>
  <br>
  <propsTest2Child2 v-bind:sendText="getChildText" />
</template>

<!-- js或ts -->
<script lang="ts">
export default {
  name: 'propsTest2'
}
</script>

<!-- js或ts -->
<script setup lang="ts">
import { ref } from 'vue'
import propsTest2Child1 from '@/components/componenttransmit/PropsTest2Child1.vue'
import propsTest2Child2 from '@/components/componenttransmit/PropsTest2Child2.vue'
//数据
let title1 = ref('props + v-bind + $attrs，父组件=>子组件=>孙组件')
let title2 = ref('props + v-bind + $attrs，父组件<=子组件<=孙组件')
let text = ref('hello')
let childText = ref('')
//方法
function changeText() {
  text.value += '-'
}
function getChildText(value: string) {
  childText.value = value
}
function changeChildText() {
  childText.value += '-'
}
</script>

<!-- 样式 -->
<style scoped></style>